$(function() {




    function load_art(id){

        console.log("loading article: "+id);

        $.ajax({
            type: 'POST',
            url: base_url+'article/article/get_article_json',
            data:{id:id},
            dataType: 'json',
            success: function(data){
                
                var json_arr = data.arr;  
                
                /*console.log("json data id: "+ json_arr[0].article_id);           
                console.log("json data datepublish: "+ json_arr[0].article_datepublish);           
                console.log("json data datepublishend: "+ json_arr[0].article_datepublishend);           
                console.log("json data datepublishhalf: "+ json_arr[0].article_datepublishhalf);           
                console.log("json data datepublishendhalf: "+ json_arr[0].article_datepublishendhalf);           
                console.log("json data title: "+ json_arr[0].article_title);           
                console.log("json data uptitle: "+ json_arr[0].article_uptitle);           
                console.log("json data intro: "+ json_arr[0].article_intro);           
                console.log("json data text: "+ json_arr[0].article_text);           
                console.log("json data status: "+ json_arr[0].article_status);           
                console.log("json data priority: "+ json_arr[0].article_priority);           
                console.log("json data user_id: "+ json_arr[0].article_user_id);
                
                console.log("json data filepath: "+ json_arr[0].media_filepath);*/
                
                var stat = '';
                switch(json_arr[0].article_status){
                    case '0':  stat = 'Kreiran u bazi'; break;
                    case '1':  stat = 'Čeka na lektora'; break;
                    case '2':  stat = 'Pregledan od lektora'; break;
                    case '3':  stat = 'Odobren od urednika'; break;
                    case '4':  stat = 'Aktivan'; break;
                    
                }
                
                //console.log("status: "+ stat);
                
                $('#main-status').html(stat);                 
                $('.preview .art_intro .text h2').html(json_arr[0].article_uptitle);
                $('.preview .art_intro .text h1').html(json_arr[0].article_title);
                $('.preview .art_intro .text p').html(json_arr[0].article_intro);
                
                $('.preview .art_cont .column').html(json_arr[0].article_text);
                
                var folder = '';
                switch(json_arr[0].media_type){
                    case 'img':
                    folder = 'img';
                    break;
                    
                    case 'video':
                    folder = 'videos';
                    break;
                }
                
                $('.preview .img img').attr('src', base_url+'assets/mediagallery/'+folder+'/'+json_arr[0].media_filepath);
                
                
            },
            error:function(data){alert("Error: " + data);}
        });
        return false;

    }

    $('#list ul li').live('click',function(){
        var id = this.id;
        load_art(id);
        $('#list ul li').each(function(index, value){
            $(value).removeClass('selected');
            if(id==value.id){
                $(value).addClass('selected');
            }
        })            
    })

    var id = $('#list ul').children(":first").attr('id') ;
    $('#list ul').children(":first").addClass('selected') ;

   // console.log (id)
    
    //load_art(id);

}); 